package cliente.gui;

import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

import comun.dto.*;

 
public class GUIEliminarEmpleado extends JFrame {
	
	 public GUIEliminarEmpleado() {
	        initComponents();
	        this.setLocationRelativeTo(null);
	    }

	    /** This method is called from within the constructor to
	     * initialize the form.
	     * WARNING: Do NOT modify this code. The content of this method is
	     * always regenerated by the Form Editor.
	     */
	    @SuppressWarnings("unchecked")
	    // <editor-fold defaultstate="collapsed" desc="Generated Code">
	    private void initComponents() {

	    	 jLayeredPane1 = new javax.swing.JLayeredPane();
	         jLabel1 = new javax.swing.JLabel();
	         cuitEmpresa = new javax.swing.JTextField();
	         buscar = new javax.swing.JButton();
	         jScrollPane1 = new javax.swing.JScrollPane();
	         tablaEmpleados = new javax.swing.JTable();
	         jLabel2 = new javax.swing.JLabel();
	         eliminar = new javax.swing.JButton();
	         cancelar = new javax.swing.JButton();

	         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
	         setTitle("Eliminar Empleado");
	    

	         jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Eliminar Empleado"));

	         jLabel1.setText("Cuit Empresa: ");
	         jLabel1.setBounds(10, 30, 90, 14);
	         jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
	         cuitEmpresa.setBounds(100, 30, 140, 20);
	         jLayeredPane1.add(cuitEmpresa, javax.swing.JLayeredPane.DEFAULT_LAYER);

	         buscar.setText("Buscar");
	         buscar.setBounds(270, 30, 90, 23);
	         jLayeredPane1.add(buscar, javax.swing.JLayeredPane.DEFAULT_LAYER);

	         tablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
	             new Object [][] {

	             },
	             new String [] {
	                 "Nombre", "Apellido", "Cuil", "Categoria", "Fecha de Ingreso"
	             }
	         ) {
	             Class[] types = new Class [] {
	                 java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
	             };

	             public Class getColumnClass(int columnIndex) {
	                 return types [columnIndex];
	             }
	         });
	         jScrollPane1.setViewportView(tablaEmpleados);

	         jLabel2.setText("Listado de Empleados:");

	         eliminar.setText("Eliminar");

	         cancelar.setText("Cancelar");

	         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
	         getContentPane().setLayout(layout);
	         layout.setHorizontalGroup(
	             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	             .addGroup(layout.createSequentialGroup()
	                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
	                     .addGroup(layout.createSequentialGroup()
	                         .addContainerGap()
	                         .addComponent(jLabel2))
	                     .addGroup(layout.createSequentialGroup()
	                         .addGap(150, 150, 150)
	                         .addComponent(eliminar)
	                         .addGap(59, 59, 59)
	                         .addComponent(cancelar))
	                     .addGroup(layout.createSequentialGroup()
	                         .addContainerGap()
	                         .addComponent(jLayeredPane1))
	                     .addGroup(layout.createSequentialGroup()
	                         .addContainerGap()
	                         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)))
	                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
	         );
	         layout.setVerticalGroup(
	             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
	             .addGroup(layout.createSequentialGroup()
	                 .addContainerGap()
	                 .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
	                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                 .addComponent(jLabel2)
	                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
	                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
	                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
	                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
	                     .addComponent(cancelar)
	                     .addComponent(eliminar))
	                 .addContainerGap(23, Short.MAX_VALUE))
	         );

	         pack();
	     }// </editor-fold>

	     
	     // Variables declaration - do not modify
	     private javax.swing.JButton buscar;
	     private javax.swing.JButton cancelar;
	     private javax.swing.JTextField cuitEmpresa;
	     private javax.swing.JButton eliminar;
	     private javax.swing.JLabel jLabel1;
	     private javax.swing.JLabel jLabel2;
	     private javax.swing.JLayeredPane jLayeredPane1;
	     private javax.swing.JScrollPane jScrollPane1;
	     private javax.swing.JTable tablaEmpleados;
	    // End of variables declaration


	     /**
	      * @return the buscar
	      */
	     public javax.swing.JButton getBuscar() {
	         return buscar;
	     }

	     /**
	      * @param buscar the buscar to set
	      */
	     public void setBuscar(javax.swing.JButton buscar) {
	         this.buscar = buscar;
	     }

	     /**
	      * @return the cancelar
	      */
	     public javax.swing.JButton getCancelar() {
	         return cancelar;
	     }

	     /**
	      * @param cancelar the cancelar to set
	      */
	     public void setCancelar(javax.swing.JButton cancelar) {
	         this.cancelar = cancelar;
	     }

	     /**
	      * @return the cuitEmpresa
	      */
	     public javax.swing.JTextField getCuitEmpresa() {
	         return cuitEmpresa;
	     }

	     /**
	      * @param cuitEmpresa the cuitEmpresa to set
	      */
	     public void setCuitEmpresa(javax.swing.JTextField cuitEmpresa) {
	         this.cuitEmpresa = cuitEmpresa;
	     }

	     /**
	      * @return the eliminar
	      */
	     public javax.swing.JButton getEliminar() {
	         return eliminar;
	     }

	     /**
	      * @param eliminar the eliminar to set
	      */
	     public void setEliminar(javax.swing.JButton eliminar) {
	         this.eliminar = eliminar;
	     }
	     
	     public javax.swing.JTable getTablaEmpleados() {
	         return tablaEmpleados;
	     }

	 
	
	 	public void insertarFila(){
			String[] filavacia=new String[4];
			DefaultTableModel m=(DefaultTableModel)tablaEmpleados.getModel();
			m.addRow(filavacia);
			tablaEmpleados.setModel(m);

		}

	 	
		public void setTablaEmpleados(){
			tablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
					new Object [][] {
							{null, null, null, null, null}
					},
					new String [] {
							"Nombre","Apellido", "Cuil","Categoria","Fecha de Ingreso"
					}
					));
		}
		
		public void setTablaEmpleados(java.util.Vector  empleados){
			EmpleadoDTO empl;
			int i=0;
			Object datos[]=new Object[4];
			while (!empleados.isEmpty()){
				DefaultTableModel m=(DefaultTableModel)tablaEmpleados.getModel();
				String[] filavacia=new String[4];
				m.addRow(filavacia);
				empl=(EmpleadoDTO) empleados.get(0);
				tablaEmpleados.setValueAt(empl.getNombre(), i, 0);
				tablaEmpleados.setValueAt(empl.getApellido(), i, 1);
				tablaEmpleados.setValueAt(empl.getCuil(), i, 2);
				tablaEmpleados.setValueAt(empl.getCategoria().getNombre(), i, 3);
				 
				tablaEmpleados.setValueAt(empl.getFechaIngreso(),i,4);
		 		
				empleados.remove(0);
				i++;
				
			}
		}
		
		public void setTablaEmpleado(){
			tablaEmpleados.setModel(new javax.swing.table.DefaultTableModel(
					new Object [][] {
						
					},
					new String [] {
							"Nombre","Apellido", "Cuil", "Categoria", "Fecha de Ingreso"
					}
					));
		}
		
		public void setTablaEmpleado(int fila){
			int i=tablaEmpleados.getRowCount()-1;
			while (fila<i){			
				tablaEmpleados.setValueAt(tablaEmpleados.getValueAt(fila+1,0), fila, 0);
				tablaEmpleados.setValueAt(tablaEmpleados.getValueAt(fila+1,1), fila, 1);
				tablaEmpleados.setValueAt(tablaEmpleados.getValueAt(fila+1,2), fila, 2);
				tablaEmpleados.setValueAt(tablaEmpleados.getValueAt(fila+1,3), fila, 3);
				tablaEmpleados.setValueAt(tablaEmpleados.getValueAt(fila+1,4), fila, 4);		
				fila++;			
			}
			DefaultTableModel m=(DefaultTableModel)tablaEmpleados.getModel();
			m.removeRow(i);
		}
		
		
	    public void setActionListeners(ActionListener lis) {
	        eliminar.addActionListener(lis);
	        cancelar.addActionListener(lis);
	        buscar.addActionListener(lis);
	    }
}
